package com.atguigu.gulimall.product.config;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

//@EnableConfigurationProperties(ThreadPoolConfigProperties.class)
@Configuration
public class MyThreadConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(ThreadPoolConfigProperties pool){
        return new ThreadPoolExecutor(pool.getCoreSize(),   //核心线程数
                pool.getMaxSize(),   //最大线程数
                pool.getKeepAliveTime(),  //空闲线程多少秒进行关闭
                TimeUnit.SECONDS,  //时间单位（秒）
                new LinkedBlockingDeque<>(100000),  //阻塞队列，表示最多存储100000个异步任务
                Executors.defaultThreadFactory(),  //线程工厂，一般使用默认的
                new ThreadPoolExecutor.AbortPolicy());   //当达到了最大线程数，阻塞队列中也存满了，处理不过来采用的一种模式，当前这种策略就是当来了新的任务直接抛弃
    }
}
